import { appItem, compoItem, detailItems, detailParam, sourceItem, sourceParam, tenantItem } from './model/sourceStatisticModel';
import { measurementHttp } from '/@/utils/http/axios';

enum Api {
  GET_SOURCE_STATISTIC_LIST = '/v1/measurement/resource/overview',
  GET_APP_LIST = '/v1/measurement/resource/appList',
  GET_COMPO_LIST = '/v1/measurement/resource/componentList',
  GET_TENANT_LIST = '/v1/measurement/resource/tenantList',
  GET_DETAIL_LIST = '/v1/measurement/resource/detail',
}

//获取资源分析表格
export const getSourceStatisticList = async (params: sourceParam) => {
  const res = await measurementHttp.post<sourceItem[]>({
    url: Api.GET_SOURCE_STATISTIC_LIST,
    params,
  });

  return res;
};
//获取资源分析表格上方form中的应用列表
export const getAppList = async () => {
  const res = await measurementHttp.get<appItem[]>({ url: Api.GET_APP_LIST });

  const result = res.map((item) => {
    return {
      label: item.appName,
      value: item.appId,
    };
  });

  return result;
};
//获取资源分析表格上方form中的组件列表
export const getCompoList = async (params: number[]) => {
  const res = await measurementHttp.post<compoItem[]>({ url: Api.GET_COMPO_LIST, params });

  const result = res.map((item) => {
    return {
      label: item.componentName,
      value: item.componentId,
    };
  });

  return result;
};
//获取资源分析表格上方form中的租户列表
export const getTenantList = async () => {
  const res = await measurementHttp.get<tenantItem[]>({ url: Api.GET_TENANT_LIST });

  const result = res.map((item) => {
    return {
      label: item.tenantName,
      value: item.tenantCode,
    };
  });

  return result;
};

//查看详情chart信息
export const getDetailList = async (params: detailParam) => {
  const res = await measurementHttp.post<detailItems[]>({ url: Api.GET_DETAIL_LIST, params });

  return res;
};
